class AddGatheredBalanceToOrders < ActiveRecord::Migration
  def self.up
    add_column :orders, :gathered_balance,:decimal,:precision => 8, :scale => 2, :default => 0
    if not Rails.env.test?      
      Enterprise.all.each do |enterprise|
        Thread.current[:current_user_id] = enterprise.admin_id
        enterprise.orders.each do |order|
          order.reset_gathered_balance!
        end
      end
    end
  end

  def self.down
    remove_column :orders, :gathered_balance
  end
end
